package cn.edu.ctbu.datajpa.controller;

import cn.edu.ctbu.datajpa.domain.Admin;
import cn.edu.ctbu.datajpa.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class AdminController {

    @Autowired
    AdminService adminService;

    @RequestMapping("/admin/List")
    public String list(HttpServletRequest httprequest, Model model){

        HttpSession session=httprequest.getSession();

        if(session.getAttribute("userid")==null){

            return "redirect:/login/user";
        }

        List<Admin> admins = adminService.findAll();

        model.addAttribute("data", admins);

        return "/admin/List";

    }

}
